﻿// <copyright file="PartialTemplateWizard.cs" company="T4 Toolbox Team">
//  Copyright © T4 Toolbox Team. All Rights Reserved.
// </copyright>

namespace T4Toolbox.VisualStudio
{
    using System;
    using System.IO;
    using EnvDTE;

    /// <summary>
    /// Clears custom tool for all files with .tt extension in a Visual Studio 
    /// project item template.
    /// </summary>
    /// <remarks>
    /// Partial templates are not meant to be transformed by T4 directly. They are 
    /// included and transformed as part of a larger T4 script.
    /// </remarks>
    [CLSCompliant(false)]
    public class PartialTemplateWizard : ProjectItemTemplateWizard
    {
        /// <summary>
        /// Runs custom wizard logic when a project item has finished generating.
        /// </summary>
        /// <param name="projectItem">
        /// The project item that finished generating.
        /// </param>
        public override void ProjectItemFinishedGenerating(ProjectItem projectItem)
        {
            if (projectItem == null)
            {
                throw new ArgumentNullException("projectItem");
            }

            string fileExtension = Path.GetExtension(projectItem.Name);
            if (fileExtension == ".tt")
            {
                Property customTool = projectItem.Properties.Item("CustomTool");
                customTool.Value = string.Empty;
            }
        }
    }
}
